﻿using System;
using System.IO;
using log4net;
using log4net.Config;

namespace Commons
{
    public class LogHelper
    {
        public static readonly ILog loginfo = LogManager.GetLogger("loginfo"); //选择<logger name="loginfo">的配置 

        public static readonly ILog logerror = LogManager.GetLogger("logerror"); //选择<logger name="logerror">的配置 

        public static void SetConfig()
        {
            XmlConfigurator.Configure();
        }

        /// <summary>
        /// 设置文件路径
        /// </summary>
        /// <param name="configFile"></param>
        public static void SetConfig(FileInfo configFile)
        {
            XmlConfigurator.Configure(configFile);
        }

        /// <summary>
        /// 写系统信息日志
        /// </summary>
        /// <param name="info"></param>
        public static void WriteLog(string info)
        {
            if (loginfo.IsInfoEnabled)
            {
                loginfo.Info(info);
            }
        }

        /// <summary>
        /// 写错误日志
        /// </summary>
        /// <param name="Error"></param>
        /// <param name="se"></param>
        public static void WriteLog(string Error, Exception se)
        {
            if (logerror.IsErrorEnabled)
            {
                logerror.Error(Error, se);
            }
        }
    }
}